/**
 * 
 */
package cn.penciltim.smstoexcel;

import java.io.File;
import java.io.IOException;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

/**
 * @author penciltim
 * 
 */
public class WriterJxl implements IWriter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.penciltim.smsToExcel.IWriter#write(cn.penciltim.smsToExcel.Sms[],
	 * java.io.File)
	 */
	public void write(Sms[] smsArray, File file) throws IOException,
			RowsExceededException, WriteException {
		WritableWorkbook wb = Workbook.createWorkbook(file);
		WritableSheet ws = wb.createSheet("我们的短信", 0);
		int r = 0;
		for (Sms sms : smsArray) {
			WritableCell cell0 = new Label(0, r, sms.getSender());
			WritableCell cell1 = new Label(1, r, sms.getReciever());
			WritableCell cell2 = new Label(2, r, sms.getTime());
			WritableCell cell3 = new Label(3, r, sms.getContent());
			ws.addCell(cell0);
			ws.addCell(cell1);
			ws.addCell(cell2);
			ws.addCell(cell3);
			r++;
		}
		wb.write();
		wb.close();
	}
}
